# 购物：
#         1.用户的账户里有钱
#         2.用户可推一个空的购物车进商场
#         3.开始购物，将自己想要的商品添加购物车
#         4.打印购物小条
# 1.现在用户在进商场之前需要从10张优惠券中，随机抽取一张优惠券。
# 比如抽到一个空凋的8折优惠券，后面在购物的过程中，空凋就可以按照8折后的价格来购买。
# 2.优化购物小条的人性化打印。
# 	购物时间，卡余额，购物数量，购买总商品的价值。
# 3.添加退货功能。在购买途中，某个商品不要了，退回到购物架中！
import datetime
import random

money = int(input("money:"))
goods = ["苹果","香蕉","葡萄","矿泉水","牛奶","豆腐","火腿"]
goods_number = []
goods_price = {'苹果': 5,'香蕉': 3,'葡萄': 4,'矿泉水': 2,'牛奶': 5,'豆腐': 3,'火腿': 5}
goods_coupon = ['2折优惠券', '3折优惠券', '4折优惠券', '5折优惠券', '6折优惠券', '7折优惠券', '8折优惠券',
                '500减100','1000减300', '5000减1000']
cart = []

my_coupon = random.choice(goods_coupon)
print(f"恭喜！您获得优惠券：{my_coupon}")
while True:
    print("欢迎光临!当前商品有苹果,香蕉,葡萄,矿泉水,牛奶,豆腐,火腿")
    print("输入Q或q: 退出购物,输入return:退货")
    my_goods = input("请输入您要购买的商品名：")
    if my_goods in goods:
        print("您要购买的商品是：",my_goods)
        print("单价是：",goods_price[my_goods])
        numbers = int(input("请输入购买数量："))
        if money >= goods_price[my_goods]*numbers:
            cart.append(my_goods)
            goods_number.append(numbers)
            money -= goods_price[my_goods]*numbers
            print(f"恭喜，购买{my_goods}成功！您的卡余额还剩",money)
        else:
            print("穷鬼，钱不够！请到其他超市购买！")
            break
    elif my_goods == "q" or my_goods == "Q":
        print("欢迎下次光临！")
        break
    elif my_goods == "return":
        my_good = input("请输入要退货的商品：")
        if my_good in cart:
             n = int(input("请输入退货数量"))
             index = cart.index(my_good)
             numbe = goods_number[index]
             if n == numbe:
                 cart.remove(my_good)
                 goods_number[index] -= n
                 money += goods_price[my_good] * n
                 print(f"退货{my_good}{n}成功")
             elif n < numbe:
                 goods_number[index] -= n
                 money += goods_price[my_good] * n
                 print(f"退货{my_good}{n}成功")
             else:
                 print("退货数量大于购买数量")
                 print("退货失败")
        else:
            print("购物车中没有这个商品，别瞎弄！")
    else:
        print("没有这个商品，别瞎弄！")

sum = 0
print("购物小条如下：")
for my_goods in cart:
    index = cart.index(my_goods)
    numbe = goods_number[index]
    print(f"商品:{my_goods},单价:{goods_price[my_goods]},购买数量:{numbe}")
    sum += goods_price[my_goods] * numbe
    temp = sum
if my_coupon == "500减100":
    if sum >= 500:
        sum -= 100
elif my_coupon == "1000减300":
    if sum >= 1000:
        sum -= 300
elif my_coupon == "5000减1000":
    if sum >= 5000:
        sum -= 1000
elif my_coupon == "2折优惠券":
    sum *= 0.2
elif my_coupon == "3折优惠券":
    sum *= 0.3
elif my_coupon == "4折优惠券":
    sum *= 0.4
elif my_coupon == "5折优惠券":
    sum *= 0.5
elif my_coupon == "6折优惠券":
    sum *= 0.6
elif my_coupon == "7折优惠券":
    sum *= 0.7
else:
    sum *= 0.8
print("总价格:",sum)
print("卡余额:",money+temp-sum)
print("购物时间:",datetime.datetime.now())